#include <cstdio>
struct nod{
    char name[11];
    char gender;
    char id[11];
    int grade;
}tmp,ma,fe;
int main()
{
    ma.grade=101;//初始化
    fe.grade=-1;
    int num;
    scanf("%d",&num);
    while(num--)
    {
        scanf("%s %c%s%d",tmp.name,&tmp.gender,tmp.id,&tmp.grade);
        if('M'==tmp.gender)
        {
            if(tmp.grade<ma.grade)
            {
                ma=tmp;
            }
        }else if(tmp.grade>fe.grade)
        {
            fe=tmp;
        }
    }
    if(fe.grade!=-1)printf("%s %s\n",fe.name,fe.id);
    else printf("Absent\n");
    if(ma.grade!=101)printf("%s %s\n",ma.name,ma.id);
    else printf("Absent\n");
    if(-1==fe.grade||101==ma.grade)printf("NA\n");
    else printf("%d\n",fe.grade-ma.grade);
    return 0;
}
